﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcOesVietNam.Models;//

namespace MvcOesVietNam.Controllers
{
    public class HomeController : Controller
    {
        //Kết nối CSDL
        DataClassesDataContext db = new DataClassesDataContext();

        #region Trang chủ (Index)
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region Giới thiệu (About)
        public ActionResult About()
        {
            return View();
        }
        #endregion

        #region Dịch vụ (Services)
        public ActionResult Services()
        {
            return View();
        }
        #endregion

        #region Khách hàng (Partner)
        public ActionResult Partner()
        {
            ViewBag.ThoiTrang = (from khtb in db.KhachHangTieuBieus
                                 where khtb.MaDMWeb == 1
                                 where khtb.AnHien == true
                                 orderby khtb.NgayHoanThanh descending
                                 select khtb).ToList();


            ViewBag.MyPham = (from khtb in db.KhachHangTieuBieus
                              where khtb.MaDMWeb == 2
                              where khtb.AnHien == true
                              orderby khtb.NgayHoanThanh descending
                              select khtb).ToList();

            ViewBag.DoTreEm = (from khtb in db.KhachHangTieuBieus
                               where khtb.MaDMWeb == 3
                               where khtb.AnHien == true
                               orderby khtb.NgayHoanThanh descending
                               select khtb).ToList();

            ViewBag.NoiThat = (from khtb in db.KhachHangTieuBieus
                               where khtb.MaDMWeb == 4
                               where khtb.AnHien == true
                               orderby khtb.NgayHoanThanh descending
                               select khtb).ToList();

            ViewBag.GiaDung = (from khtb in db.KhachHangTieuBieus
                               where khtb.MaDMWeb == 5
                               where khtb.AnHien == true
                               orderby khtb.NgayHoanThanh descending
                               select khtb).ToList();

            ViewBag.DienMay = (from khtb in db.KhachHangTieuBieus
                               where khtb.MaDMWeb == 6
                               where khtb.AnHien == true
                               orderby khtb.NgayHoanThanh descending
                               select khtb).ToList();

            ViewBag.Khac = (from khtb in db.KhachHangTieuBieus
                            where khtb.MaDMWeb == 7
                            where khtb.AnHien == true
                            orderby khtb.NgayHoanThanh descending
                            select khtb).ToList();

            return View();
        }
        #endregion

        #region Chi tiết Khách hàng (PartnerDetails)
        public ActionResult PartnerDetails(int id)
        {
            //Lấy ra KhachHangTieuBieu từ MaCty truyền vào
            var CT_KHTB = (db.KhachHangTieuBieus.First(khtb => khtb.MaCty == id));

            //Lấy ra Hình chụp trang web của KH từ id truyền vào
            ViewBag.HinhChupWebKH = (from hc in db.HinhChupWebKHs
                                     where hc.MaCty == id && hc.AnHien == true
                                     orderby hc.MaHinhChup ascending
                                     select hc).ToList();

            //Bộ đếm lượt xem
            CT_KHTB.LuotXem += 1;
            UpdateModel(CT_KHTB);
            db.SubmitChanges();

            return View(CT_KHTB);
        }
        #endregion

        #region Bảng giá (Price)
        public ActionResult Price()
        {
            return View();
        }
        #endregion

        #region Tuyển dụng (Recruitment)
        public ActionResult Recruitment()
        {
            return View();
        }
        #endregion

        #region Liên hệ (Contact)
        public ActionResult Contact()
        {
            return View();
        }
        #endregion

        #region Tài khoản (Login)
        #region Đăng nhập (Login)
        [HttpGet]
        [ChildActionOnly]//Gọi từ View sang Controll
        public ActionResult _pLogin()
        {
            return PartialView();
        }
        #endregion
        #endregion
    }
}
